package TestModel;

import java.util.LinkedList;

import VisibilityGraph.NeighboursHash;

import DataModel.CommonLibrary.CommonDefs;
import DataModel.LayoutManager.CRectangle;
import junit.framework.TestCase;


public class neighboursTest extends TestCase {
	CRectangle u1;
	CRectangle u2;
	CRectangle u3;
	CRectangle u4;
	CRectangle u5;
	
	LinkedList<CRectangle> urecs;
	
	public void testNeighbours() {
		setUpTest();
		
		NeighboursHash nei = new NeighboursHash(urecs);
		LinkedList<CRectangle> res=null;

		System.out.println("Neighbours of " + u1.toString()+" in x direction :");
		res = nei.getNeighbours(u1, 'x');
		assertTrue("Error in neighbours of "+u1.toString(),res!=null && res.size()==1 && res.contains(u4));
		if (res !=null) CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u1.toString()+" in y direction :");
		res = nei.getNeighbours(u1, 'y');
		assertTrue("Error in neighbours of "+u1.toString(),res!=null && res.size()==1 && res.contains(u5));
		if (res !=null)	CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u2.toString()+" in x direction :");
		res = nei.getNeighbours(u2, 'x');
		assertTrue("Error in neighbours of "+u2.toString(),res==null);
		if (res !=null) CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u2.toString()+" in y direction :");
		res = nei.getNeighbours(u2, 'y');
		assertTrue("Error in neighbours of "+u2.toString(),res!=null && res.size()==1 && res.contains(u3));
		if (res !=null)	CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u3.toString()+" in x direction :");
		res = nei.getNeighbours(u3, 'x');
		assertTrue("Error in neighbours of "+u3.toString(),res==null);
		if (res !=null) CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u3.toString()+" in y direction :");
		res = nei.getNeighbours(u3, 'y');
		assertTrue("Error in neighbours of "+u3.toString(),res!=null && res.size()==1 && res.contains(u2));
		if (res !=null)	CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u4.toString()+" in x direction :");
		res = nei.getNeighbours(u4, 'x');
		assertTrue("Error in neighbours of "+u4.toString(),res!=null && res.size()==1 && res.contains(u1));
		if (res !=null) CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u4.toString()+" in y direction :");
		res = nei.getNeighbours(u4, 'y');
		assertTrue("Error in neighbours of "+u4.toString(),res!=null && res.size()==1 && res.contains(u5));
		if (res !=null)	CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u5.toString()+" in x direction :");
		res = nei.getNeighbours(u5, 'x');
		assertTrue("Error in neighbours of "+u5.toString(),res==null);
		if (res !=null) CRectangle.printRecsList(res);
		
		System.out.println("Neighbours of " + u5.toString()+" in y direction :");
		res = nei.getNeighbours(u5, 'y');
		assertTrue("Error in neighbours of "+u5.toString(),res!=null && res.size()==2 && res.contains(u1)&&res.contains(u4));
		if (res !=null)	CRectangle.printRecsList(res);
		
		
		
	}

	private void setUpTest() {
		u1 = new CRectangle(1,2,3,6,CommonDefs.Layer.Metal1,1);
		u2 = new CRectangle(2,5,7,7,CommonDefs.Layer.Metal1,2);
		u3 = new CRectangle(2,0,7,3,CommonDefs.Layer.Metal1,3);
		u4 = new CRectangle(6,2,10,6,CommonDefs.Layer.Metal1,4);
		u5 = new CRectangle(1,7,10,9,CommonDefs.Layer.Metal1,5);
		urecs =  new LinkedList<CRectangle>();
		urecs.add(u1);
		urecs.add(u2);
		urecs.add(u3);
		urecs.add(u4);
		urecs.add(u5);
	}
	
	
	
}
